home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 January / maximum-cd-1999-01.iso / Benchmarks / 12 Step / MusicMatch Jukebox / mmsetup.EXE / data1.cab / Help_Files / WebHelp.cab / hhapplet / TabButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-27  |  3.0 KB  |  166 lines

  1. package hhapplet;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10. import java.awt.image.ImageObserver;
  11.  
  12. public class TabButton extends CanvasButton {
  13.    protected String label;
  14.    protected int x_offset = -1;
  15.    protected int y_offset = -1;
  16.    protected Font active;
  17.    protected Font inactive;
  18.    protected int tab_x;
  19.    protected int tab_y;
  20.    protected int tab_width;
  21.    protected int tab_height;
  22.  
  23.    public void reshape(int var1, int var2, int var3, int var4) {
  24.       super.reshape(var1, var2, var3, var4);
  25.       this.tab_x = var1;
  26.       this.tab_y = var2;
  27.       this.tab_width = var3;
  28.       this.tab_height = var4;
  29.       this.centerText();
  30.    }
  31.  
  32.    public TabButton(String var1) {
  33.       int var2 = WebHelp.GetFontSize();
  34.       this.active = new Font(WebHelp.GetFontName(), 1, var2);
  35.       this.inactive = new Font(WebHelp.GetFontName(), 0, var2);
  36.       ((Component)this).setFont(this.inactive);
  37.       this.label = var1;
  38.    }
  39.  
  40.    public void paint(Graphics var1) {
  41.       var1.setColor(((Component)this).getBackground());
  42.       var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
  43.       if (super.img != null) {
  44.          var1.drawImage(super.img, 2, 2, (ImageObserver)null);
  45.       } else if (this.label != null) {
  46.          if (this.x_offset == -1 || this.y_offset == -1) {
  47.             this.centerText();
  48.          }
  49.  
  50.          var1.setColor(((Component)this).getForeground());
  51.          var1.setFont(((Component)this).getFont());
  52.          var1.drawString(this.label, this.x_offset, this.y_offset);
  53.       }
  54.  
  55.       if (super.button_push_state) {
  56.          this.paintBorderIn(var1);
  57.       } else {
  58.          this.paintBorderOut(var1);
  59.       }
  60.    }
  61.  
  62.    public void paintBorderOut(Graphics var1) {
  63.       Rectangle var2 = ((Component)this).bounds();
  64.       Color var3 = ((Component)this).getBackground().brighter();
  65.       Color var4 = var3.darker();
  66.       Color var5 = var4.darker();
  67.       Color var6 = var5.darker();
  68.       var1.setColor(var5);
  69.       var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
  70.       var1.setColor(var6);
  71.       var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 2);
  72.       var1.setColor(var4);
  73.       var1.drawLine(1, 1, var2.width - 2, 1);
  74.       var1.drawLine(1, 1, 1, var2.height - 2);
  75.       if (((Component)this).isEnabled()) {
  76.          var1.drawLine(0, var2.height - 1, var2.width, var2.height - 1);
  77.       }
  78.  
  79.       var1.setColor(var3);
  80.       var1.drawLine(1, 0, var2.width - 2, 0);
  81.       var1.drawLine(0, 1, 0, var2.height - 2);
  82.       if (((Component)this).isEnabled()) {
  83.          var1.drawLine(0, var2.height - 2, var2.width, var2.height - 2);
  84.       }
  85.  
  86.    }
  87.  
  88.    public void paintBorderIn(Graphics var1) {
  89.       Rectangle var2 = ((Component)this).bounds();
  90.       Color var3 = ((Component)this).getBackground().brighter();
  91.       Color var4 = var3.darker();
  92.       Color var5 = var4.darker();
  93.       Color var6 = var5.darker();
  94.       var1.setColor(var6);
  95.       var1.drawLine(0, 0, var2.width - 1, 0);
  96.       var1.drawLine(0, 0, 0, var2.height - 1);
  97.       var1.setColor(var5);
  98.       var1.drawLine(1, 1, var2.width - 2, 1);
  99.       var1.drawLine(1, 1, 1, var2.height - 2);
  100.       var1.setColor(var4);
  101.       var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
  102.       var1.setColor(var3);
  103.       var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
  104.    }
  105.  
  106.    public void disable() {
  107.       if (((Component)this).isEnabled()) {
  108.          ((Component)this).setFont(this.active);
  109.          super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
  110.          this.centerText();
  111.          ((Component)this).repaint();
  112.          super.disable();
  113.       }
  114.  
  115.    }
  116.  
  117.    public void enable() {
  118.       if (!((Component)this).isEnabled()) {
  119.          ((Component)this).setFont(this.inactive);
  120.          super.reshape(this.tab_x, this.tab_y + 3, this.tab_width, this.tab_height - 3);
  121.          this.centerText();
  122.          ((Component)this).repaint();
  123.          super.enable();
  124.       }
  125.  
  126.    }
  127.  
  128.    public void enable(boolean var1) {
  129.       if (var1) {
  130.          this.enable();
  131.       } else {
  132.          this.disable();
  133.       }
  134.    }
  135.  
  136.    public Dimension preferredSize() {
  137.       try {
  138.          if (super.img != null) {
  139.             return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
  140.          } else if (this.label != null) {
  141.             FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  142.             int var2 = var1.stringWidth(this.label);
  143.             int var3 = var1.getMaxAscent();
  144.             var2 += 4 + 2 * var1.getMaxAdvance();
  145.             var3 += 4 + var1.getMaxDescent();
  146.             return new Dimension(var2, var3);
  147.          } else {
  148.             return new Dimension(20, 20);
  149.          }
  150.       } catch (Exception var4) {
  151.          return new Dimension(20, 20);
  152.       }
  153.    }
  154.  
  155.    protected void centerText() {
  156.       Rectangle var1 = ((Component)this).bounds();
  157.       FontMetrics var2 = ((Component)this).getFontMetrics(((Component)this).getFont());
  158.       int var3 = var2.stringWidth(this.label);
  159.       int var4 = var2.getMaxAscent();
  160.       this.y_offset = var1.height - var4;
  161.       this.y_offset = this.y_offset / 2 + var4;
  162.       this.x_offset = var1.width - var3;
  163.       this.x_offset /= 2;
  164.    }
  165. }
  166.